const path = require('path')
const webpack = require('webpack')

var htmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
    entry: {
        app: './src/js/main.js',
        vendor: ['react', 'react-dom']
    },
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'js/[name]-[hash:5].js',
        publicPath: '',
        library: "someLibName",
        libraryTarget: "umd",
        auxiliaryComment: "Test Comment"
    },
    module: {
        rules: [
            {
                test: /\.jsx?$/, 
                include: path.resolve(__dirname, 'src/js'),
                exclude: path.resolve(__dirname, 'node_modules'), 
                use: {
                    loader: 'babel-loader'
                }
            },
            {
                test: /\.css$/,
                loader: ExtractTextPlugin.extract({
                            use: 'css-loader',
                        })
                }
        ]
    },
    devServer: {
        contentBase: './dist',
        compress: true,
        port: 9000,
        hot: true,
        host: "0.0.0.0",
        open: true
    },
    devtool: 'inline-source-map',
    plugins: [
        new CleanWebpackPlugin(['dist']),
        // new webpack.DefinePlugin({
        //     'process.env': {
        //         NODE_ENV: '"production"'
        //     }
        // }),
        // new webpack.HotModuleReplacementPlugin(),
        new htmlWebpackPlugin({
            template: 'index.html',
            filename: 'index.html',
            inject: 'body',
            title: 'html-webpack-plugin',
            minify: {
                removeComments: true,
                collapseWhitespace: true
            }
        }),
        new ExtractTextPlugin('style.bundle.css'),
        // new webpack.optimize.UglifyJsPlugin(),
        // new webpack.optimize.CommonsChunkPlugin('test.js')
    ]
}
